package class1;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Random;

public class RandId {
   private static int counter;//赋值到了哪一个编号
    private int id;//标识编号

    static {
        GregorianCalendar today=new GregorianCalendar();
        int y=today.get(Calendar.YEAR);
        int m=today.get(Calendar.MONTH)+1;
        int d=today.get(Calendar.DATE);
        System.out.printf("今天是%04d年%02d月%02d日\n",y,m,d);
        //Random rand=new Random();
        //counter=rand.nextInt(10)*100;//不可以存在return语句，也不可以使用this或super
        counter=y*1000000+m*10000+d*100;
    }

    public RandId(){//构造函数
        id=++counter;
    }//构造函数，每次调用构造函数counter+1
    public int getId(){
        return id;
    }

    public static void main(String[] args) {
        RandId a=new RandId();
        RandId b=new RandId();
        RandId c=new RandId();
        System.out.println("a的标识编号："+a.getId());
        System.out.println("b的标识编号："+b.getId());
        System.out.println("c的标识编号："+c.getId());
    }
}
